from django.db import models


# Create your models here.
# 物料类型
class Category(models.Model):
    name = models.CharField(default="", max_length=50, verbose_name="物料名称")
    remark = models.CharField(default="", max_length=255, verbose_name="备注")
    is_delete = models.IntegerField(default=0, verbose_name="是否删除")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")


# 物料
class Supply(models.Model):
    name = models.CharField(default="", max_length=50, verbose_name="物料名称")
    number = models.IntegerField(default=0, verbose_name="数量")
    remark = models.CharField(default="", max_length=255, verbose_name="备注")
    is_delete = models.IntegerField(default=0, verbose_name="是否删除")
    category = models.ForeignKey(to='Category', on_delete=models.CASCADE, verbose_name='物料类型', null=True)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

    def __str__(self):
        return self.name


# 出入库记录
class InAndOutRecord(models.Model):
    order_no = models.CharField(max_length=30, verbose_name="记录单编号", default="")
    order_type = models.IntegerField(default=0, verbose_name="出入库类型")   # 0-未知，1-入库，2-出库
    supply = models.ForeignKey(to='Supply', on_delete=models.CASCADE, verbose_name='物料', null=True)
    number = models.IntegerField(default=0, verbose_name="出入库数量")
    cur_number = models.IntegerField(verbose_name="当前库存数量", null=True)
    last_number = models.IntegerField(verbose_name="出入库前数量", null=True)
    img_url = models.CharField(max_length=255, verbose_name="图片凭证")
    remark = models.CharField(max_length=255, verbose_name="备注")
    operator = models.CharField(max_length=20, verbose_name='操作人', null=True)
    status = models.IntegerField(default=0, verbose_name="记录单状态")       # 0-待确认，1-确认，2-取消
    confirm_time = models.DateTimeField(verbose_name="确认时间", null=True)
    confirm_user = models.CharField(max_length=20, verbose_name='确认人', null=True)
    is_delete = models.IntegerField(default=0, verbose_name="是否删除")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

